#include "sensor_device.h"

int sensor_device::sensor_read_regs(void)
{
    uint16_t tab_rp_bits[32];
    int rc = modbus_read_registers(ctx, 0x0100, 0x09, tab_rp_bits);
    if (rc == -1 ) {
        printf("ERROR modbus_read_bits single (%d)\n", rc);
        printf("address = %d\n", 0);
    } 
}

int sensor_device::sensor_writereg_point(u_int16_t point_position)
{
    int rc = modbus_write_register(ctx, 0x0102, point_position);
    if(rc == -1 && errno == EMBBADDATA)
    {
        return -1;
    }
    return DP_SUCCESS;
}
int sensor_device::sensor_writereg_name(u_int16_t gas_name)
{
    int rc = modbus_write_register(ctx, 0x0103, gas_name);
    if(rc == -1 && errno == EMBBADDATA)
    {
        return -1;
    }
    return DP_SUCCESS;
}
int sensor_device::sensor_writereg_unit(u_int16_t unit)
{
    int rc = modbus_write_register(ctx, 0x0104, unit);
    if(rc == -1 && errno == EMBBADDATA)
    {
        return -1;
    }
    return DP_SUCCESS;
} 
int sensor_device::sensor_writereg_maxlimit(u_int16_t maxlimit)
{
    int rc = modbus_write_register(ctx, 0x0105, maxlimit);
    if(rc == -1 && errno == EMBBADDATA)
    {
        return -1;
    }
    return DP_SUCCESS;
}
int sensor_device::sensor_writereg_minlimit(u_int16_t minlimit)
{
    int rc = modbus_write_register(ctx, 0x0106, minlimit);
    if(rc == -1 && errno == EMBBADDATA)
    {
        return -1;
    }
    return DP_SUCCESS;   
}
int sensor_device::sensor_writereg_address(u_int16_t address)
{
    int rc = modbus_write_register(ctx, 0x0107, address);
    if(rc == -1 && errno == EMBBADDATA)
    {
        return -1;
    }
    return DP_SUCCESS;   
}
int sensor_device::sensor_writereg_range(u_int16_t range)
{
    int rc = modbus_write_register(ctx, 0x0108, range);
    if(rc == -1 && errno == EMBBADDATA)
    {
        return -1;
    }
    return DP_SUCCESS;  
}
int sensor_device::sensor_writereg_zeroAdjustment(u_int16_t value)
{
    int rc = modbus_write_register(ctx, 0x0110, 0x00aa);
    if(rc == -1 && errno == EMBBADDATA)
    {
        return -1;
    }
    return DP_SUCCESS;  
}
int sensor_device::sensor_writereg_calValue(u_int16_t value)
{
    int rc = modbus_write_register(ctx, 0x0111, value);
    if(rc == -1 && errno == EMBBADDATA)
    {
        return -1;
    }
    return DP_SUCCESS;  
}
int sensor_device::sensor_writereg_calFactor(u_int16_t value)
{
    int rc = modbus_write_register(ctx, 0x0112, 0x00aa);
    if(rc == -1 && errno == EMBBADDATA)
    {
        return -1;
    }
    return DP_SUCCESS;  
}